<script lang="ts" setup>
import OrderRequest from '@/request/orderRequest';
import to from '@/utils/to';
import Tools from '@/utils/tools';

const rescueData = ref<IEmergOrdAssgnSvrRes[]>([]);

onLoad((options) => {
  if (!options) return;
  if (!options.orderId) return;
  fetchObtainRescueProgressData(Number(options.orderId));
});

// 获取救援进度
const fetchObtainRescueProgressData = async (orderId: number) => {
  const [err, res] = await to(OrderRequest.EmergOrdAssgnSvr({ orderId, hasLoading: true }));
  if (err) return;
  rescueData.value = res.data.filter((item) => item.firstAidDate);
};
</script>
<template>
  <view class="c-pd" v-if="rescueData.length > 0">
    <view class="mb-12px c-br bg-white c-pd" v-for="(item, index) in rescueData" :key="index">
      <view class="flex justify-between items-center">
        <view class="flex items-center">
          <i class="i-gravity-ui:persons mr-8px"></i>
          {{ item.waiterName }}
        </view>
        <view v-if="item.phone" class="flex items-center" @click="Tools.callPhone(item.phone)">
          <i class="i-solar:phone-linear mr-8px"></i>
          {{ Tools.ProtectingPhoneNumbers(item.phone) }}
        </view>
      </view>
      <van-divider />
      <view class="flex justify-between">
        <text>救援状态</text>
        <van-tag type="success" v-if="item.jobType === 1">取AED中</van-tag>
        <van-tag type="primary" v-if="item.jobType === 2">救援中</van-tag>
      </view>
      <view class="flex justify-between c-text-12 c-text-color-grey mt-8px">
        <text>参与救援时间</text>
        <text>{{ item.firstAidDate }}</text>
      </view>
    </view>
  </view>
  <van-empty v-else description="暂无数据" />
</template>
